package com.buer.train.common.utils;

import java.math.BigDecimal;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by Administrator on 2021/1/26.
 */
public class CommonGeneratorUtil {

    private static final AtomicLong LAST_TIME_MS = new AtomicLong();

    public static long uniqueCurrentTimeMS() {
        long now = System.currentTimeMillis();
        while(true) {
            long lastTime = LAST_TIME_MS.get();
            if (lastTime >= now)
                now = lastTime+1;
            if (LAST_TIME_MS.compareAndSet(lastTime, now))
                return now;
        }
    }

    //生产ID
    public static BigDecimal generatorId(){
        String s = uniqueCurrentTimeMS() + "";
        String i = (int) ((Math.random() * 9 + 1) * 100000)+"";
        String generatorId = s + i;

        return new BigDecimal(generatorId);
    }

    //生成装备表ProdCode
    public static String generatorProdCode(){
        long time=uniqueCurrentTimeMS();
        return "ZB"+time;
    }


    //生成装备类别表Code
    public static String generatorCategoryCode(){
        long time=uniqueCurrentTimeMS();
        return "PC"+time;
    }

    //生成RFID
    public static String generatorRfid(){
        long time=uniqueCurrentTimeMS();
        return "FD"+time;
    }

    //生成车辆二级分类编号
    public static String generatorCarCategory(){
        long time=uniqueCurrentTimeMS();
        return "CC"+time;
    }

    //入库订单表订单编号
    public static String generatorPutOrderNum(){
        long time=uniqueCurrentTimeMS();
        return "PS"+time;
    }


    //出库订单表订单编号
    public static String generatorOutOrderNum(){
        long time=uniqueCurrentTimeMS();
        return "OS"+time;
    }

    //出库订单表订单编号
    public static String generatorOaBatchNo(){
        long time=uniqueCurrentTimeMS();
        return "CHYSRK"+time;
    }

    //出库订单表订单编号
    public static String generatorEmergencyBatchNo(){
        long time=uniqueCurrentTimeMS();
        return "EM"+time;
    }

    //盘点订单表订单编号
    public static String generatorCheckOrderNo(){
        long time=uniqueCurrentTimeMS();
        return "CK"+time;
    }

    //销毁订单表订单编号
    public static String generatorDestoryOrderNum(){
        long time=uniqueCurrentTimeMS();
        return "DS"+time;
    }

    public static void main(String[] args){
        System.out.println(generatorOaBatchNo());
    }
}
